package com.jy.wms.controller;

import com.joyi.gate.comm.SessionInfo;
import com.joyi.gate.safety.vo.UserInfo;
import com.jy.wms.common.SetStatus;
import com.jy.wms.common.base.*;
import com.jy.wms.pojo.SysHz;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.jy.wms.pojo.WmsBox;
import com.jy.wms.service.WmsBoxService;
import javax.servlet.http.HttpSession;
import com.github.pagehelper.Page;

import java.util.List;
import com.jy.wms.common.UUIDUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * @ClassName: WmsBoxController
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @Author Jane
 * @Date Wed Oct 25 10:02:09 CST 2017
 */
@RestController
@RequestMapping("/wmsbox")
@Api(value = "/wmsbox", description = "")
public class  WmsBoxController extends BaseController<WmsBoxService,WmsBox> {

    @PostMapping(value = "selectZxmx")
    @ApiOperation(value = "查询装箱明细",response = JSONObject.class, notes = "查询装箱明细")
    public @ResponseBody JSONObject getWmsBox(@RequestBody WmsBox entity,HttpSession session) {
        JSONObject json = getJSONObject();
        try {
            json=baseService.selectZxmxByFydid(entity);
        }catch (Exception e){
            e.printStackTrace();
        }
        return json;
    }
    @PostMapping(value = "printeZxmx/{ssyqdid}")
    @ApiOperation(value = "打印装箱明细",response = JSONObject.class, notes = "查询装箱明细")
    public @ResponseBody JSONObject getPrinteZxmx(@PathVariable String ssyqdid,HttpSession session) {
        JSONObject json = getJSONObject();
        try {
            UserInfo userinfo= (UserInfo) session.getAttribute(SessionInfo.USER_INFO);
            String ckmc=userinfo.getUser().getOrgName();
            String show_rent=userinfo.getUser().getShow_rent();
            String telephone=userinfo.getOrgs().get(0).getTelephone();
            String dz=userinfo.getUser().getAddress();
            json=baseService.selectDyxxByFydid(ssyqdid,ckmc,show_rent,telephone,dz);
        }catch (Exception e){
            e.printStackTrace();
        }
        return json;
    }

    @PostMapping(value = "boxZx")
    @ApiOperation(value = "发运订单 装箱",response = JSONObject.class, notes = "发运订单 装箱")
    public @ResponseBody JSONObject boxZx(@RequestBody SetAndModifyModel  setModel,HttpSession session) {
        try{
            List<SysHz> hz=(List<SysHz>)session.getAttribute(BaseSessionInfo.SessionConsignor);
            UserInfo userinfo= (UserInfo) session.getAttribute(SessionInfo.USER_INFO);
            baseService.casingContainerazation(setModel.getIds(),userinfo.getUser().getOrgId().get(0).toString(),hz.get(0).getHzid().toString());
            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(),ReturnType.success.toString(),"装箱成功","", "");
        }catch (ServiceException e){
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(),ReturnType.error.toString(),"装箱失败",e.getMessage(),"");
        }catch (Exception e){
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(),ReturnType.error.toString(),"装箱失败",e.getMessage(),"");
        }
    }
    @PostMapping(value = "againBoxZx")
    @ApiOperation(value = "发运订单 再次装箱",response = JSONObject.class, notes = "发运订单 再次装箱")
    public @ResponseBody JSONObject againBoxZx(@RequestBody SetAndModifyModel  setModel,HttpSession session) {
        try{
            List<SysHz> hz=(List<SysHz>)session.getAttribute(BaseSessionInfo.SessionConsignor);
            UserInfo userinfo= (UserInfo) session.getAttribute(SessionInfo.USER_INFO);
            baseService.casingContainerazation(setModel.getIds(),userinfo.getUser().getOrgId().get(0).toString(),hz.get(0).getHzid().toString());
            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(),ReturnType.success.toString(),"再次装箱成功","",  "");
        }catch (ServiceException e){
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(),ReturnType.error.toString(),"再次装箱失败",e.getMessage(),"");
        }catch (Exception e){
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(),ReturnType.error.toString(),"再次装箱失败",e.getMessage(),"");
        }
    }
    @PostMapping(value = "cancelBoxZx")
    @ApiOperation(value = "发运订单 取消装箱",response = JSONObject.class, notes = "发运订单 取消装箱")
    public @ResponseBody JSONObject cancelBoxZx(@RequestBody SetAndModifyModel  setModel,HttpSession session) {
        try{

            baseService.cancelEncasement(setModel.getIds());
            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(),ReturnType.success.toString(),"取消装箱成功","",  "");
        }catch (ServiceException e){
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(),ReturnType.error.toString(),"取消装箱失败",e.getMessage(),"");
        }catch (Exception e){
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(),ReturnType.error.toString(),"取消装箱失败",e.getMessage(),"");
        }
    }
}
